package com.littleken.foodiePojo.enums;

/*
 * Create by littleken on 2020/11/23 14:13
 */
public enum  SexEnum {
    SEX_MAN(1,"男"),
    SEX_WOMAN(0,"女"),
    SEX_UNKNOW(2,"保密");

    private Integer code;
    private String desc;

    SexEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 通过 CODE 获取 DESC
     * @param code
     * @return
     */
    public static String getDescByCode(Integer code) {
        for (SexEnum sex :SexEnum.values()) {
            if (sex.code.equals(code)) {
                return sex.desc;
            }
        }
        return null;
    }

    /**
     * 通过 DESC 获取 CODE
     * @param desc
     * @return
     */
    public static Integer getCodeByDesc(String desc) {
        for (SexEnum sex : SexEnum.values()) {
            if (sex.desc.equals(desc)) {
                return sex.code;
            }
        }
        return null;
    }

    /**
     * 通过 CODE 获取 Enum
     * @param code
     * @return
     */
    public static SexEnum getEnumByCode(Integer code) {
        for (SexEnum sex :SexEnum.values()) {
            if (sex.code.equals(code)) {
                return sex;
            }
        }
        return null;
    }

}
